/**
 * AlertServiceImpl.java
 * Created at 2018-1-5
 * Created by zhanghailin
 * Copyright (C) 2018 BROADTEXT SOFTWARE, All rights reserved.
 */
package com.broadtext.app.alert.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.broadtext.app.alert.service.AlertService;
import com.broadtext.common.exp.DaoException;
import com.broadtext.common.repository.EntityDao;
import com.broadtext.common.service.impl.EntityServiceImpl;
import com.broadtext.common.utils.DateUtils;
import com.broadtext.rms.system.dao.IAlertQueryDao;
import com.broadtext.rms.system.model.TtPackCustomAlert;

/**
 * <p>ClassName: AlertServiceImpl</p>
 * <p>Description: TODO</p>
 * <p>Author: zhanghailin</p>
 * <p>Date: 2018-1-5</p>
 */
@Service("alertService")
public class AlertServiceImpl extends EntityServiceImpl<TtPackCustomAlert> implements AlertService{
    
    @Autowired
    @Qualifier("alertQueryDao")
    private IAlertQueryDao alertQueryDao;
    
    
    
    /**
     * 
     * <p>
     * Description: 注解入相关DAO
     * </p>
     * 
     * @param entityDao
     */
    @Autowired
    @Qualifier("alertQueryDao")
    public void setEntityDao(EntityDao<TtPackCustomAlert> entityDao) {
        super.entityDao = entityDao;
    }

    /** (non-Javadoc)
     * <p>Title: findPackAlertDataList</p>
     * <p>Description: 获取告警页面数据list</p>
     * @param params
     * @return
     * @see com.broadtext.app.alert.service.AlertService#findPackAlertDataList(java.util.Map)
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Object> findPackAlertDataList(Map<String, Object> params) {
        List<Object> list = new ArrayList<Object>();
        String happenTimeStart = DateUtils.getDayStartStr(new Date());
        String happenTimeEnd = DateUtils.getDayEndStr(new Date());
        params.put("happenTimeStart", happenTimeStart);
        params.put("happenTimeEnd", happenTimeEnd);
        try {
            list = this.entityDao.findByProperty("com.broadtext.rms.system.model.TtPackCustomAlert.findPackAlertDataListNew", params);
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return list;
    }

    /** (non-Javadoc)
     * <p>Title: findPackAlertDetailInfo</p>
     * <p>Description: </p>
     * @param params
     * @return
     * @see com.broadtext.app.alert.service.AlertService#findPackAlertDetailInfo(java.util.Map)
     */
    @SuppressWarnings("unchecked")
    @Override
    public Map<String, Object> findPackAlertDetailInfo(Map<String, Object> params) {
        List<Map<String, Object>> list;
        try {
            list = this.entityDao.findByProperty("com.broadtext.rms.system.model.TtPackCustomAlert.findPackAlertDetailInfoNew", params);
            if(list!=null&&list.size()>0){
                return list.get(0);
            }
        } catch (DaoException e) {
            e.printStackTrace();
        }
        
        return null;
    }

    /** (non-Javadoc)
     * <p>Title: findAlertQueryParams</p>
     * <p>Description: 获取告警查询条件</p>
     * @return
     * @see com.broadtext.app.alert.service.AlertService#findAlertQueryParams()
     */
    @SuppressWarnings("unchecked")
    @Override
    public Map<String, Object> findAlertQueryParams() {
        Map<String, Object> data = new HashMap<String, Object>();
        try {
            List<Object> alertLevelList = this.entityDao.findByProperty("com.broadtext.rms.system.model.TtPackCustomAlert.findAllAlertLevels", null);
            data.put("alertLevelList", alertLevelList);
            List<Object> alertNameList = this.entityDao.findByProperty("com.broadtext.rms.system.model.TtPackCustomAlert.findAllAlertNames", null);
            data.put("alertNameList", alertNameList);
            List<Object> packModelList = this.entityDao.findByProperty("com.broadtext.rms.system.model.TtPackCustomAlert.findAllPackModels", null);
            data.put("packModelList", packModelList);
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return data;
    }

    /** (non-Javadoc)
     * <p>Title: findPackAlertHistoryData</p>
     * <p>Description: </p>
     * @param params
     * @return
     * @see com.broadtext.app.alert.service.AlertService#findPackAlertHistoryData(java.util.Map)
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Object> findPackAlertHistoryData(Map<String, Object> params) {
        List<Object> list = new ArrayList<Object>();
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String happenTimeEnd = f.format(new Date());
        String happenTimeStart = DateUtils.getPastDate(7); 
        params.put("happenTimeStart", happenTimeStart);
        params.put("happenTimeEnd", happenTimeEnd);
        try {
            list = this.entityDao.findByProperty("com.broadtext.rms.system.model.TtPackCustomAlert.findPackAlertHistoryDataNew", params);
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return list;
    }

    /** (non-Javadoc)
     * <p>Title: findAlertHistoryData</p>
     * <p>Description: 查询电池告警历史数据</p>
     * @param params
     * @return
     * @see com.broadtext.app.alert.service.AlertService#findAlertHistoryData(java.util.Map)
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Object> findAlertHistoryData(Map<String, Object> params) {
        List<Object> list = new ArrayList<Object>();
        try {
            list = this.entityDao.findByProperty("com.broadtext.rms.system.model.TtPackCustomAlert.findAlertHistoryDataNew", params);
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return list;
    }

    /** (non-Javadoc)
     * <p>Title: getAlertCount</p>
     * <p>Description: </p>
     * @param params
     * @return
     * @see com.broadtext.app.alert.service.AlertService#getAlertCount(java.util.Map)
     */
    @Override
    public Long getAlertCount(Map<String, Object> params) {
        Long count = this.alertQueryDao.getAlertCount(params);
        return count;
    }

}
